define([
     'u/common/app'
	],function(){
	(function(){
	window.lm_load_more=Class.extend({
		init:function(params) {
            var self = this;
            this.ele = params.ele;
			this.list = params.list;
			this.success = params.success;
			self.start();
			if(typeof self.Operating=="function"){
				self.Operating()
			}
        },
		start:function() {
			var self = this;
			$(self.ele).each(function(index, element) {
                var T=$(this);
                  $(window).bind('scroll', function() {
					  var url=T.data("url");
				      var method=T.attr("method");
					  var page=parseInt($(self.ele).attr("data-page"));
                      if($(document).scrollTop() + $(window).height() >= $(document).height()-50) {
				              if(page > 1 &&!$(self.ele).hasClass("on")) {
								$(self.ele).addClass("on");
								//$(".lm_load_more").show()
                                $.ajax({
                                        type: method?method:"post",
                                        url: url,
                                        data: {page:page,targetId:$("[name=targetId]").val()},
                                        dataType: "json",
                                        success: function(e) {
										   if(typeof self.success=="function"){
											   self.success(e,page)
											}
											setTimeout(function(){$(self.ele).removeClass("on")},200);
                                         },
                                         error: function(XMLHttpRequest, textStatus, errorThrown) {
                                                    alert(errorThrown);
                                         }
                                   });
                             }
                         }
                 });
				
            });
			 autoMore()
			function autoMore(){
					  var url=self.ele.data("url");
					  var method=self.ele.attr("method");
					  var page=parseInt($(self.ele).attr("data-page"));
						if(page==1){
							$(self.ele).addClass("on");
							  $.ajax({
								type: method?method:"post",
								url: url,
								data: {lastId:page,targetId:$("[name=targetId]").val()},
								dataType: "json",
								success: function(e) {
								   if(typeof self.success=="function"){
									        self.success(e,page)
									}
									setTimeout(function(){$(self.ele).removeClass("on")},200);
								 },
								 error: function(XMLHttpRequest, textStatus, errorThrown) {
											alert(errorThrown);
								 }
						   });
					 }
						
		}
			$("body,html").animate({"scrollTop":0},0)
		 }
		
	})
})()
});